package com.sensetime.opencvdemo;

import android.graphics.Bitmap;

/**
 * Created by ChineseBoy on 2017/7/19.
 */

public class ImageProcessUtils {

    /**
     * 毛玻璃一张图片
     * @param srcBitmap    原始图片
     * @return  毛玻璃后的图片
     */
    public static Bitmap blur(Bitmap srcBitmap){
        int width = srcBitmap.getWidth();
        int height = srcBitmap.getHeight();
        int[] pixels = new int[width * height];
        srcBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        blurImage(pixels, width, height);
        Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        return newBitmap;
    }

    public static Bitmap lighten(Bitmap srcBitmap,int value) {
        int width = srcBitmap.getWidth();
        int height = srcBitmap.getHeight();
        int[] pixels = new int[width * height];
        srcBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        lightenImage(pixels, width, height,value);
        Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        return newBitmap;
    }

    public static native void lightenImage(int[] pixels, int w, int h,int lightenValue);
    public static native void blurImage(int[] pixels, int w, int h);
    public static native void calculatePCA(float[] deepthValues);

    static {
        System.loadLibrary("native-lib");
        System.loadLibrary("opencv_java3");
    }
}
